//
//  HelpAlertView.m
//  GC_OC
//
//  Created by tuibian  on 2022/5/27.
//

#import "HelpAlertView.h"

@interface HelpAlertView ()
@property(nonatomic, strong)UIView *bgView;
@end

@implementation HelpAlertView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.bgView = [UIView new];
        self.bgView.backgroundColor= XHUIColorFromRGBA(0x000000, 0.24);
        [self addSubview:self.bgView];
        
        UIView *coverView = [UIView new];
        coverView.backgroundColor = [UIColor whiteColor];
        coverView.layer.masksToBounds = YES;
        coverView.layer.cornerRadius = 8;
        [self.bgView addSubview:coverView];
        
        UILabel *title = [UILabel new];
        title.text = @"帮助与说明";
        title.textAlignment = NSTextAlignmentCenter;
        title.textColor = [UIColor blackColor];
        title.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
        [coverView addSubview:title];
        
        UIButton *backButton = [UIButton new];
        [backButton setImage:[UIImage imageNamed:@"icon清空32default备2"] forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        [coverView addSubview:backButton];
        
        UILabel *content = [UILabel new];
//        [content setValue:[NSNumber numberWithInt:20] forKey:@"lineSpacing"];
        content.text = @"1:用户获取mp3格式链接，在结尾 添加#（分割符），例如\n\nhttp://chiatsolar.com/1.mp3 \nhttp://chiatsolar.com/2.mp3\n\n 分别是名称是，“1节期”，“2节期”\n\n http://chiatsolar.com/1.mp3#1节期\n http://chiatsolar.com/2.mp3#2节期\n\n 这样的格式即可，如果格式不对无法导入。 值得注意，一行一个音频#标题";
        content.preferredMaxLayoutWidth = SCREEN_WIDTH - 47 - 38 - 23 - 16;
        content.numberOfLines = 0;
        content.textColor = [UIColor blackColor];
        content.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        [coverView addSubview:content];
        
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        
        [coverView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgView).offset(47);
            make.right.equalTo(self.bgView).offset(-38);
            make.top.equalTo(self.bgView).offset(122);
//            make.height.mas_equalTo(339);
        }];
        [title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(coverView).offset(47);
            make.right.equalTo(coverView).offset(-38);
            make.top.equalTo(coverView).offset(15);
            make.height.mas_equalTo(25);
        }];
        [backButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(coverView).offset(-11);
            make.centerY.equalTo(title).offset(0);
            make.height.width.mas_equalTo(32);
        }];
        [content mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(coverView).offset(23);
            make.right.equalTo(coverView).offset(-16);
            make.top.equalTo(title.mas_bottom).offset(15);
//            make.height.mas_equalTo(25);
            make.bottom.equalTo(coverView.mas_bottom).offset(-24);
        }];
        self.alpha = 0.0;
        
    }
    return self;
}

- (void)showIn:(UIView *)view {
    self.frame = view.bounds;
    [view addSubview:self];
    
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.alpha = 1.0;
    } completion:nil];
}

- (void)back {
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.alpha = 0.0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
@end
